<template>
  <div class="storeout">
    <!-- 导航栏 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>出仓单管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索框 -->
    <el-card class="search">
      <el-input
        class="input"
        v-model="input"
        placeholder="请输入关键字"
      ></el-input>
      <!-- 搜索按钮 -->
      <el-button
        type="primary"
        icon="el-icon-search"
        style="margin-left: 6px"
      ></el-button>
    </el-card>
    <!-- 主页面 -->
    <el-card class="main">
      <!-- 表格主体 -->
      <el-row>
        <el-table
          :data="
            dataList.slice((currentPage - 1) * pagesize, currentPage * pagesize)
          "
          border
          style="width: 100%"
        >
          <el-table-column label="客户" type="index" width="150">
            <template slot-scope="scope">
              <span>{{ scope.row.buyer }}</span>
            </template></el-table-column
          >
          <el-table-column label="操作员" width="140px">
            <template slot-scope="scope">
              <span>{{ scope.row.operator }}</span>
            </template>
          </el-table-column>
          <el-table-column label="出仓费" width="140px">
            <template slot-scope="scope">
              <span>{{ scope.row.postfare }}</span>
            </template>
          </el-table-column>
          <el-table-column label="销售订单号" width="140px">
            <template slot-scope="scope">
              <span>{{ scope.row.slid }}</span>
            </template>
          </el-table-column>
          <el-table-column label="出仓单号" width="140px">
            <template slot-scope="scope">
              <span text-align="center">{{ scope.row.soid }}</span>
            </template>
          </el-table-column>
          <el-table-column label="出仓时间" width="140px">
            <template slot-scope="scope">
              <span text-align="center">{{ scope.row.sotime }}</span>
            </template>
          </el-table-column>

          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="success"
                icon="el-icon-check"
                @click="show(scope.row)"
                >查看</el-button
              >
              <el-button
                size="mini"
                type="danger"
                icon="el-icon-delete"
                @click="deleteList(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageTotal"
      >
      </el-pagination>

      <!-- 弹出详细出仓单信息 -->
      <el-dialog
        title="出仓单详细信息"
        :visible.sync="editdialogVisible"
        width="60%"
      >
        <template>
          <el-descriptions direction="vertical" :column="2" border>
            <el-descriptions-item label="客户简称">{{
              nowmessage.buyer
            }}</el-descriptions-item>
            <el-descriptions-item label="出仓日期">{{
              nowmessage.sotime
            }}</el-descriptions-item>
            <el-descriptions-item label="销售单号">{{
              nowmessage.slid
            }}</el-descriptions-item>
            <el-descriptions-item label="出仓单号">{{
              nowmessage.soid
            }}</el-descriptions-item>
          </el-descriptions>
          <el-table :data="nowmessage.solist" stripe style="width: 100%">
            <el-table-column prop="pid" label="商品编号"> </el-table-column>
            <el-table-column prop="numUnit" label="出仓数量"> </el-table-column>
            <el-table-column prop="num" label="件数"> </el-table-column>
            <el-table-column prop="price" label="单价"> </el-table-column>
            <el-table-column prop="total" label="总金额"></el-table-column>
            <el-table-column label="件号">
              <template slot-scope="scope">
                <el-dropdown size="small" split-button type="primary">
                  查看件号
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item
                      v-for="(item, index) in scope.row.jianid"
                      :key="index"
                      >{{
                        "件号：" + item.jianID + "&nbsp;库位：" + item.kuwei
                      }}</el-dropdown-item
                    >
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
import { getAll, deleteList } from "../../network/StoreoutManage";
export default {
  data() {
    return {
      index: 0, //粗略列表的序号
      radio: "1",
      cfid: "",
      checkflag: 1,
      ischeck: false,
      input: "",
      query: "",
      currentPage: 1,
      pagesize: 5,
      adddialogVisible: false,
      editdialogVisible: false,
      state: "正常",
      addCfList: {},
      dataList: [], //装进仓单粗略信息
      nowmessage: {},
      changeList: [], //装改变后的数据
      pageTotal: Number,
    };
  },
  created() {
    getAll().then((response) => {
      this.dataList = response.data.obj;
      this.pageTotal = this.dataList.length;
      for (var i = 0; i < this.dataList.length; i++) {
        this.dataList[i].solist = JSON.parse(this.dataList[i].solist);
      }
      console.log(this.dataList);
      // for (var i = 0; i < this.dataList.length; i++) {
      //     this.dataList[i].solist = JSON.parse(this.dataList[i].solist);
      //   }
    });
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    getlist() {},
    handleSizeChange(val) {
      console.log(val);
      this.pagesize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    handleClose(done) {
      // this.$confirm("确认关闭？")
      //   .then((_) => {
      //     done();
      //   })
      //   .catch((_) => {});
    },
    show(row) {
      this.editdialogVisible = true;
      this.nowmessage = row;
    },

    deleteList(scope) {
      console.log(scope);
      this.$confirm("确认删除该单据？")
        .then((_) => {
          deleteList({ id: scope.soid }).then((res) => {
            console.log(res);
            if (res.data.code == "200") {
              this.$message({
                message: res.data.status,
                type: "success",
              });
              getAll().then((response) => {
                this.dataList = response.data.obj;
                this.pageTotal = this.dataList.length;
                for (var i = 0; i < this.dataList.length; i++) {
                  this.dataList[i].solist = JSON.parse(this.dataList[i].solist);
                }
              });
            } else {
              this.$message(res.data.status);
            }
          });
        })
        .catch((_) => {});
    },
  },
};
</script>
<style scoped>
.input {
  width: 30%;
}
.el-breadcrumb {
  margin-bottom: 15px;
  font-size: 12px;
}
.btn {
  margin-left: 880px;
}
.el-table {
  margin-top: 15px;
}
.el-pagination {
  text-align: center;
}
.main,
.search {
  margin-inline: 15px;
  min-height: 100%;
  height: 100%;
}
.head {
  margin-top: 10px;
}
.input {
  width: 300px;
}
.main {
  margin-top: 5px;
}
</style>